import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import { logins } from "../utils/api";
export default new Vuex.Store({
  state: {
    token: "", //存放数据
  },
  getters: {},
  mutations: {
    login(state, token) {
      state.token = token;
      localStorage.setItem("token", token);
    },
  },
  actions: {
    login({ commit }, form) {
    return  new Promise((resolve, reject) => {
        logins(form).then((res) => {
          console.log(res);
          resolve(res);
          commit("login", res.data.data.token);
        });
      });
    },
  },
  modules: {},
});
